<script setup lang='ts'>
  import { onMounted, reactive, ref } from 'vue';
  import { propApi } from '@/api/controller';
  import { giftClassifyList } from '@/pinia/getter';
  import { Toastloading } from '@/utils/public';
  import xmImage from '@/components/xmImage/index.vue';
  import Pagination from "@/components/Pagination/index.vue";
  import JackpotList from './JackpotList.vue';
  const JackpotListRef = ref()
  const action = reactive({
    total:0,
    list:[] as any[],
  })
  const listQuery = reactive({
    page: 1,
    limit: 20,
    gift_id: "",
    gift_name: "",
    gift_type:6
  })
  const handleSerach = () => {
    listQuery.page = 1;
    getList();
  };
  const resetQuery = () => {
    Object.assign(listQuery, {
      page: 1,
      limit: 20,
      gift_id: "",
      gift_name: "",
      gift_type:6
    });
  };
  const handleForm = (row:any = {})=>{
    JackpotListRef.value.openDialog(row)
  }
  const getList = async()=> {
    const loading = Toastloading()
    const res = await propApi.getGifts(listQuery)
    loading.close()
    const { data=[], total=0, } = res?.data || {}
    action.total = total
    action.list = data
  }
  onMounted(()=>{
    getList()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">礼物ID：</div>
          <el-input v-model="listQuery.gift_id" placeholder="请输入礼物ID"/>
        </div>
        <div class="labelItem">
          <div class="label">礼物名称：</div>
          <el-input v-model="listQuery.gift_name" placeholder="请输入礼物名称"/>
        </div>
      </div>
      <div class="labelBox">
        <div class="labelItem">
          <el-button type="primary" @click="handleSerach">查询</el-button>
          <el-button type="primary" @click="resetQuery">重置</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border
    >
      <el-table-column width="100" prop="gift_id" label="礼物ID" />
      <el-table-column min-width="120" show-overflow-tooltip prop="name" label="礼物名称" />
      <el-table-column width="140" prop="image" label="礼物图片">
        <template #default="scoped">
          <xmImage :src="scoped.row.image" :list="[scoped.row.image]" />
        </template>
      </el-table-column>
      <el-table-column min-width="120" sortable prop="price" label="价格" />
      <el-table-column min-width="120" prop="giftName" label="是否显示礼物">
        <template #default="scoped">
          {{ ['否','是'][scoped.row.is_show] || '' }}
        </template>
      </el-table-column>
      <el-table-column min-width="120" prop="giftName" align="center" label="类型">
        <template #default="scoped">
          {{ giftClassifyList.find(res=>res.type == scoped.row.gift_type)?.label || scoped.row.gift_type }}
        </template>
      </el-table-column>
      <el-table-column width="140" fixed="right" label="操作">
        <template #default="scoped">
          <el-button type="primary" @click="handleForm(scoped.row)">查看礼物池</el-button>
        </template>
      </el-table-column>
    </el-table>
    <Pagination v-show="action.total > 0" :total="action.total" v-model:page="listQuery.page"
      v-model:limit="listQuery.limit" @pagination="getList" />
      <JackpotList ref="JackpotListRef" @update-list="getList" />
  </div>
</template>
